package com.letv.android.client.utils;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.os.Handler;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.ScaleAnimation;
import android.view.inputmethod.InputMethodManager;
import android.widget.PopupWindow;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.letv.android.young.client.R;
import com.letv.android.client.view.PublicLoadLayout;
import com.letv.android.client.view.PublicLoadLayoutPlayerLibs;
import com.letv.core.bean.TipMapBean.TipBean;
import com.letv.core.constant.LetvConstant.DialogMsgConstantId;
import com.letv.core.utils.LetvCommonDialog;
import com.letv.core.utils.TipUtils;

import java.lang.reflect.InvocationTargetException;

public class UIs {

    private static String packageName;
    private static String packageSearchName = "com.letv.lesophoneclient";

    /**
     * 创建一个公共的加载布局
     * */
    public static PublicLoadLayout createLoadPage(Context context, int layoutId) {
        return createLoadPage(context, layoutId, false);
    }

    /**
     * 创建一个公共的加载布局
     * 
     * @param context
     * @param layoutId
     * @param isToFrameLayout
     * 是否将内容添加到FrameLayout中
     * @return
     */
    public static PublicLoadLayout createLoadPage(Context context, int layoutId, boolean isToFrameLayout) {

        PublicLoadLayout rootView = new PublicLoadLayout(context);
        rootView.addContent(layoutId, isToFrameLayout);

        return rootView;
    }

    /**
     * 创建一个公共的加载布局
     * */
    public static PublicLoadLayoutPlayerLibs createPage(Context context, int layoutId) {
        return createPage(context, layoutId, false);
    }

    /**
     * 创建一个公共的加载布局
     * 
     * @param context
     * @param layoutId
     * @param isToFrameLayout
     * 是否将内容添加到FrameLayout中
     * @return
     */
    public static PublicLoadLayoutPlayerLibs createPage(Context context, int layoutId, boolean isToFrameLayout) {

        PublicLoadLayoutPlayerLibs rootView = new PublicLoadLayoutPlayerLibs(context);
        rootView.addContent(layoutId, isToFrameLayout);

        return rootView;
    }

    /**
     * 根据资源ID得到View
     * */
    public static View inflate(Context context, int resource, ViewGroup root, boolean attachToRoot) {
        return LayoutInflater.from(context).inflate(resource, root, attachToRoot);
    }

    /**
     * 根据资源ID得到View
     * */
    public static View inflate(Context context, int resource, ViewGroup root) {
        return LayoutInflater.from(context).inflate(resource, root);
    }

    public static int[] measure(View v) {
        int w = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
        int h = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
        v.measure(w, h);
        int width = v.getMeasuredWidth();
        int height = v.getMeasuredHeight();
        return new int[] { width, height };
    }

    /**
     * 根据资源ID得到View
     * */
    public static View inflate(LayoutInflater inflater, int resource, ViewGroup root, boolean attachToRoot) {
        return inflater.inflate(resource, root, attachToRoot);
    }

    /**
     * 将一倍尺寸缩放到当前屏幕大小的尺寸（宽）
     * */
//    public static int zoomWidth(int w) {
//        int sw = 0;
//        sw = Math.min(getScreenWidth(), getScreenHeight());
//
//        return Math.round(w * sw / 320f + 0.5f);
//    }

    public static int zoomWidth(Context context,int w) {
        int sw = 0;
        sw = Math.min(getScreenWidth(context), getScreenHeight(context));

        return Math.round(w * sw / 320f + 0.5f);
    }

    /**
     * 将一倍尺寸缩放到当前屏幕大小的尺寸（高）
     * */
//    public static int zoomHeight(int h) {
//        int sh = 0;
//        sh = getScreenHeight();
//
//        return (int) (h * sh / 480f + 0.5f);
//    }

    /**
     * 将一倍尺寸缩放到当前屏幕大小的尺寸（高）
     * */
//    public static int zoomRealHeight(int h) {
//        int sh = 0;
//        sh = Math.max(getScreenWidth(), getScreenHeight());
//
//        return (int) (h * sh / 480f + 0.5f);
//    }

    /**
     * 缩放控件
     * */
//    public static void zoomView(int w, int h, View view) {
//        if (view == null) {
//            return;
//        }
//
//        LayoutParams params = view.getLayoutParams();
//
//        if (params == null) {
//            return;
//        }
//
//        params.width = zoomWidth(w);
//        params.height = zoomWidth(h);
//    }

    public static void zoomView(Context context,int w, int h, View view) {
        if (view == null) {
            return;
        }

        LayoutParams params = view.getLayoutParams();

        if (params == null) {
            return;
        }

        params.width = zoomWidth(context,w);
        params.height = zoomWidth(context,h);
    }

    /**
     * 缩放控件
     * */
//    public static void zoomViewHeight(int h, View view) {
//        if (view == null) {
//            return;
//        }
//
//        LayoutParams params = view.getLayoutParams();
//
//        if (params == null) {
//            return;
//        }
//
//        params.height = zoomWidth(h);
//    }

    /**
     * 缩放控件
     * */
//    public static void zoomViewWidth(int w, View view) {
//        if (view == null) {
//            return;
//        }
//
//        LayoutParams params = view.getLayoutParams();
//
//        if (params == null) {
//            return;
//        }
//
//        params.width = zoomWidth(w);
//    }

    /**
     * 缩放控件
     * */
//    public static void zoomViewFull(View view) {
//        if (view == null) {
//            return;
//        }
//
//        LayoutParams params = view.getLayoutParams();
//
//        if (params == null) {
//            return;
//        }
//
//        params.width = getScreenWidth();
//        params.height = getScreenHeight();
//    }

    /**
     * dip转px
     * */
//    public static int dipToPx(int dipValue) {
//        final float scale = LetvSDK.getInstance().getResources().getDisplayMetrics().density;
//        int pxValue = (int) (dipValue * scale + 0.5f);
//
//        return pxValue;
//    }

    public static int dipToPx(Context context,int dipValue) {
        final float scale = context.getResources().getDisplayMetrics().density;
        int pxValue = (int) (dipValue * scale + 0.5f);

        return pxValue;
    }

    /**
     * px转dip
     * */
//    public static float dipToPxFloat(int dipValue) {
//        final float scale = LetvConstant.Global.displayMetrics.density;
//        float pxValue = dipValue * scale;
//
//        return pxValue;
//    }

    /**
     * 获取顶部状态栏高度
     * 
     * @param act
     * @return
     */
    public static int getStatusBarHeight(Activity act) {
        Rect frame = new Rect();
        act.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
        return frame.top;
    }

    /**
     * 获取标题栏高度
     * 
     * @param act
     * @return
     */
    public static int getTitleBarHeight(Activity act) {
        int contentTop = act.getWindow().findViewById(Window.ID_ANDROID_CONTENT).getTop();
        int titleBarHeight = contentTop - getStatusBarHeight(act);
        return titleBarHeight;
    }

    /**
     * 获取内容区域高度
     * 
     * @param act
     * @return
     */
//    public static int getContentHeight(Activity act) {
//        int contentTop = act.getWindow().findViewById(Window.ID_ANDROID_CONTENT).getTop();
//        return (getScreenHeight() - contentTop);
//    }

    /**
     * 得到屏幕宽度
     * */
//    public static int getScreenWidth() {
//        return ((WindowManager) LetvApplication.getInstance().getSystemService(Context.WINDOW_SERVICE))
//                .getDefaultDisplay().getWidth();
//    }

    public static int getScreenWidth(Context context) {
        return ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE))
            .getDefaultDisplay().getWidth();
    }

    /**
     * 得到屏幕高度
     * */
//    public static int getScreenHeight() {
//        return ((WindowManager) LetvApplication.getInstance().getSystemService(Context.WINDOW_SERVICE))
//                .getDefaultDisplay().getHeight();
//    }

    public static int getScreenHeight(Context context) {
        return ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE))
            .getDefaultDisplay().getHeight();
    }

    /**
     * 判断是否是横屏
     * */
    public static boolean isLandscape(Context activity) {
        if (activity == null) {
            return false;
        }

        int t = activity.getResources().getConfiguration().orientation;
        return t == Configuration.ORIENTATION_LANDSCAPE;

    }

    /**
     * 全屏
     * */
    public static void fullScreen(Activity activity) {
        activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }

    /**
     * 隐藏Title
     * */
    public static void notFullScreen(Activity activity) {
        activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }

    /**
     * 设置为横屏
     * */
    public static void screenLandscape(Activity activity) {
        activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    }

    /**
     * 设置为竖屏
     * */
    public static void screenPortrait(Activity activity) {
        activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }

    private static void showPopWin(View anchor, int layoutID, String text, boolean isCancelOutSide) {

        Context context = anchor.getContext();
        LayoutInflater inflater = LayoutInflater.from(context);
        View viewRoot = inflater.inflate(layoutID, null);
        ((TextView) viewRoot.findViewById(R.id.toast_text)).setText(text);
        viewRoot.findViewById(R.id.progress)
                .setVisibility(isCancelOutSide ? View.GONE : View.VISIBLE);
        final PopupWindow popWin = new PopupWindow(viewRoot, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        popWin.setOutsideTouchable(isCancelOutSide);
        popWin.setBackgroundDrawable(new ColorDrawable(0));
        popWin.showAtLocation(anchor, Gravity.CENTER, 0, 0);
        new Handler(anchor.getContext().getMainLooper()).postDelayed(new Runnable() {

            @Override
            public void run() {
                if (popWin.isShowing()) {
                    popWin.dismiss();
                }
            }
        }, 2000);
    }

    static Handler handler;

    /**
     * 解决 toast 退出不消失，排查原因可能与退出时消息队列未及时处理消息有关，解决法案，创建一个新的looper
     * 
     * @param txtId
     */
    // hzz
    public static void showToast2(final int txtId) {
        /*
         * ScanningMediaService.showToast(LetvApplication.getInstance(),
         * LetvApplication.getInstance().getResources().getString(txtId));
         */
    }

    // end
    public static void call(Activity activity, int messageId, DialogInterface.OnClickListener yes,
            DialogInterface.OnClickListener no) {

        if (activity == null) {
            return;
        }

        Dialog dialog = new AlertDialog.Builder(activity).setTitle(R.string.dialog_default_title)
                .setIcon(R.drawable.letv_dialog_icon).setMessage(messageId)
                .setPositiveButton(R.string.dialog_default_ok, yes).setNegativeButton(R.string.dialog_default_no, no)
                .create();

        if (!activity.isFinishing() && !activity.isRestricted()) {
            try {
                dialog.show();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    /**
     * public static void showToast(int txtId) { mToast =
     * Toast.makeText(LetvApplication.getInstance(), txtId, Toast.LENGTH_SHORT);
     * mToast.setText(txtId); mToast.setGravity(Gravity.CENTER, 0, 0);
     * mToast.setDuration(Toast.LENGTH_SHORT); mToast.show(); }
     * 
     * /** 隐藏键盘输入法
     * 
     * @param mActivity
     */
    public static void hideSoftkeyboard(Activity mActivity) {
        if (null != mActivity && null != mActivity.getCurrentFocus()) {
            InputMethodManager mInputMethodManager = (InputMethodManager) mActivity
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            if (null != mInputMethodManager) {
                mInputMethodManager.hideSoftInputFromWindow(mActivity.getCurrentFocus().getWindowToken(),
                        InputMethodManager.HIDE_NOT_ALWAYS);
            }
        }
    }

    // private static LetvToast mLetvToast = null;
    //
    // public static void setFullscreenCompatibility(Activity activity) {
    // if ("Galaxy Nexus".equals(Build.MODEL.trim()));
    // try {
    // Object localObject1 = View.class.getDeclaredField(
    // "SYSTEM_UI_FLAG_HIDE_NAVIGATION").get(View.class);
    // Class[] localObject2 = new Class[1];
    // localObject2[0] = Integer.TYPE;
    // Method localMethod = View.class.getMethod("setSystemUiVisibility",
    // localObject2);
    // View view = activity.getWindow().getDecorView();
    // Object[] arrayOfObject = new Object[1];
    // arrayOfObject[0] = localObject1;
    // localMethod.invoke(view, arrayOfObject);
    // return;
    // } catch (InvocationTargetException localInvocationTargetException) {
    // } catch (NoSuchMethodException localNoSuchMethodException) {
    // } catch (IllegalAccessException localIllegalAccessException) {
    // } catch (NoSuchFieldException localNoSuchFieldException) {
    // } catch (IllegalArgumentException localIllegalArgumentException) {
    // } catch (SecurityException localSecurityException) {
    // } catch (Exception e) {
    // }
    //

    //
    // public static void setFullscreenCompatibility(Activity activity) {
    // // if ("Galaxy Nexus".equals(Build.MODEL.trim()));
    // // try {
    // // Object localObject1 = View.class.getDeclaredField(
    // // "SYSTEM_UI_FLAG_HIDE_NAVIGATION").get(View.class);
    // // Class[] localObject2 = new Class[1];
    // // localObject2[0] = Integer.TYPE;
    // // Method localMethod = View.class.getMethod("setSystemUiVisibility",
    // // localObject2);
    // // View view = activity.getWindow().getDecorView();
    // // Object[] arrayOfObject = new Object[1];
    // // arrayOfObject[0] = localObject1;
    // // localMethod.invoke(view, arrayOfObject);
    // // return;
    // // } catch (InvocationTargetException localInvocationTargetException) {
    // // } catch (NoSuchMethodException localNoSuchMethodException) {
    // // } catch (IllegalAccessException localIllegalAccessException) {
    // // } catch (NoSuchFieldException localNoSuchFieldException) {
    // // } catch (IllegalArgumentException localIllegalArgumentException) {
    // // } catch (SecurityException localSecurityException) {
    // // } catch (Exception e) {
    // // }
    // }
    //
    // public static void playCheck(final Activity activity , int albumId ,
    // int
    // type) {
    // if (PreferencesManager.getInstance().isLogin()) {
    //
    // } else {
    // if (payType == 1 || payType == 2) {
    // call(activity, R.string.dialog_vip_login, R.string.dialog_login,
    // R.string.dialog_cancel,
    // new DialogInterface.OnClickListener() {
    //
    // @Override
    // public void onClick(DialogInterface dialog, int which) {
    // LoginActivity.launchForResult(activity, 123);
    // }
    // }, new DialogInterface.OnClickListener() {
    //
    // @Override
    // public void onClick(DialogInterface dialog, int which) {
    //
    // }
    // });
    // } else if (payType == 0) {
    // call(activity, R.string.dialog_buy_login, R.string.dialog_login,
    // R.string.dialog_cancel,
    // new DialogInterface.OnClickListener() {
    //
    // @Override
    // public void onClick(DialogInterface dialog, int which) {
    // LoginActivity.launchForResult(activity, 123);
    // }
    // }, new DialogInterface.OnClickListener() {
    //
    // @Override
    // public void onClick(DialogInterface dialog, int which) {
    //
    // }
    // });
    // }
    //
    // }
    // }
    //
    // /**
    // * 需要付费影片，弹出框
    // * */
    // public static void showNewLogin(final Activity activity, int payType,
    // final String name,
    // final int albumId, final String date, final double price) {
    // LogInfo.log("payType=" + payType + " name=" + name + " albumId=" +
    // albumId + " date="
    // + date + "  price=" + price);
    //
    // if (PreferencesManager.getInstance().isLogin()) {
    // if (payType == 1 || payType == 2) {
    // call(activity, R.string.dialog_vip_buy, R.string.dialog_buyvip,
    // R.string.dialog_cancel, new DialogInterface.OnClickListener() {
    //
    // @Override
    // public void onClick(DialogInterface dialog, int which) {
    // VipGoodsActivity.launch(activity, albumId);
    // }
    // }, new DialogInterface.OnClickListener() {
    //
    // @Override
    // public void onClick(DialogInterface dialog, int which) {
    //
    // }
    // });
    // } else if (payType == 0) {
    // call(activity, R.string.dialog_buy_buy, R.string.dialog_buy,
    // R.string.dialog_cancel, new DialogInterface.OnClickListener() {
    // @Override
    // public void onClick(DialogInterface dialog, int which) {
    // PayCentreActivity.launch(activity, "0", name, date, price, albumId,
    // null);
    // }
    // }, new DialogInterface.OnClickListener() {
    // @Override
    // public void onClick(DialogInterface dialog, int which) {
    //
    // }
    // });
    // }
    // } else {
    // if (payType == 1 || payType == 2) {
    // callDialogMsgPosNeg(activity, DialogMsgConstantId.SIX_ZERO_TWO_CONSTANT,
    // R.string.dialog_login, R.string.dialog_cancel,
    // new DialogInterface.OnClickListener() {
    //
    // @Override
    // public void onClick(DialogInterface dialog, int which) {
    // LoginActivity.launchForResult(activity, 123);
    // }
    // }, new DialogInterface.OnClickListener() {
    //
    // @Override
    // public void onClick(DialogInterface dialog, int which) {
    //
    // }
    // });
    // } else if (payType == 0) {
    // call(activity, R.string.dialog_buy_login, R.string.dialog_login,
    // R.string.dialog_cancel, new DialogInterface.OnClickListener() {
    //
    // @Override
    // public void onClick(DialogInterface dialog, int which) {
    // LoginActivity.launchForResult(activity, 123);
    // }
    // }, new DialogInterface.OnClickListener() {
    //
    // @Override
    // public void onClick(DialogInterface dialog, int which) {
    //
    // }
    // });
    // } else {
    // call(activity, R.string.dialog_buy_login, R.string.dialog_login,
    // R.string.dialog_cancel, new DialogInterface.OnClickListener() {
    //
    // @Override
    // public void onClick(DialogInterface dialog, int which) {
    // LoginActivity.launchForResult(activity, 123);
    // }
    // }, new DialogInterface.OnClickListener() {
    //
    // @Override
    // public void onClick(DialogInterface dialog, int which) {
    //
    // }
    // });
    // }
    //
    // }
    // }
    //
    // public static void showLogin(final Activity activity, int payType, final
    // String name,
    // final int albumId, final String date, final double price) {
    // /**
    // * payDate string 服务期限
    // * singlePrice string 单片价格
    // * allowMonth string 1:单点且支持包月;0:仅单点;2:仅支持包月;
    // *
    // * chargetype string 0:点播;1:点播且包月;2:包月
    // * chargeflatform string 价格,默认为0，表示对应平台无数据(平台:phone,pad)
    // * validDays string 服务期限
    // *
    // * UIs.showLogin(AlbumDetailActivity.this, album.getAllowmonth(),
    // * album.getTitle(), album.getAid(), album.getPaydate(),
    // * album.getSingleprice());
    // */
    // if (payType == -1 || date==null) {
    // new RequestAlbumPayInfoTask(activity, albumId + "", new UpdateAlbumInfo()
    // {
    // @Override
    // public void updateAlbumInfo(AlbumPayInfo mAlbumPayInfo) {
    // showNewLogin(activity, mAlbumPayInfo.getChargeflatform(), name, albumId,
    // mAlbumPayInfo.getValidDays() + "", mAlbumPayInfo.getChargeflatform());
    // }
    // }, true).start();
    // }else {
    // showNewLogin(activity, payType, name, albumId,
    // date, price);
    // }
    // }
    //

    private static LetvCommonDialog mCommonDialog;

    /**
     * 显示只有一个标题两个按钮的对话框
     * 
     * @param context
     * @param title
     * @param leftText
     * @param rightText
     */
    public static void showDialog(Activity context, CharSequence title, CharSequence leftText, CharSequence rightText,
            DialogInterface.OnClickListener leftListener, DialogInterface.OnClickListener rightListener) {
        showDialog(context, title, "", leftText, rightText, leftListener, rightListener);
    }

    public static void showDialog(Activity context, CharSequence title, CharSequence content, CharSequence leftText,
            CharSequence rightText, DialogInterface.OnClickListener leftListener,
            DialogInterface.OnClickListener rightListener) {
        if (mCommonDialog != null && mCommonDialog.isShowing())
            mCommonDialog.dismiss();
        mCommonDialog = new LetvCommonDialog(context);
        mCommonDialog.setTitle(title);
        mCommonDialog.setContent(content.toString());
        mCommonDialog.setButtonText(leftText, rightText);
        if (leftListener != null)
            mCommonDialog.setLeftOnClickListener(leftListener);
        if (rightListener != null)
            mCommonDialog.setRightOnClickListener(rightListener);
        if (!context.isFinishing() && !context.isRestricted()) {
            mCommonDialog.show();
        }
    }

    /**
     * 显示只有一个标题一个按钮的对话框
     * 
     * @param title
     * @param centerText
     */
    public static void showDialog(Activity context, CharSequence title, CharSequence centerText,
            DialogInterface.OnClickListener centerListener) {
        if (mCommonDialog != null && mCommonDialog.isShowing())
            mCommonDialog.dismiss();
        mCommonDialog = new LetvCommonDialog(context);
        mCommonDialog.setTitle(title);
        mCommonDialog.setButtonText(centerText);
        if (centerListener != null)
            mCommonDialog.setCenterOnClickListener(centerListener);
        if (!context.isFinishing() && !context.isRestricted()) {
            mCommonDialog.show();
        }
    }

    public static void call(Activity activity, int messageId, int yes, int no,
            DialogInterface.OnClickListener yesListener, DialogInterface.OnClickListener noListener) {

        if (activity == null) {
            return;
        }

        Dialog dialog = new AlertDialog.Builder(activity).setTitle(R.string.dialog_default_title)
                .setIcon(R.drawable.letv_dialog_icon).setMessage(messageId).setPositiveButton(yes, yesListener)
                .setNegativeButton(no, noListener).create();

        if (!activity.isFinishing() && !activity.isRestricted()) {
            dialog.show();
        }

    }

    //
    public static void call(Activity activity, int messageId, int yes, int no,
            DialogInterface.OnClickListener yesListener, DialogInterface.OnClickListener noListener, View view) {

        if (activity == null) {
            return;
        }

        Dialog dialog = new AlertDialog.Builder(activity).setTitle(R.string.dialog_default_title)
                .setIcon(R.drawable.letv_dialog_icon).setMessage(messageId).setView(view)
                .setPositiveButton(yes, yesListener).setNegativeButton(no, noListener).create();

        if (!activity.isFinishing() && !activity.isRestricted()) {
            dialog.show();
        }

    }

    public static boolean call(Activity activity, int messageId, int yes, int no,
            DialogInterface.OnClickListener yesListener, DialogInterface.OnClickListener noListener, View view,
            boolean cancelable) {

        if (activity == null) {
            return false;
        }

        Dialog dialog = new AlertDialog.Builder(activity).setTitle(R.string.dialog_default_title)
                .setIcon(R.drawable.letv_dialog_icon).setMessage(messageId).setCancelable(cancelable).setView(view)
                .setPositiveButton(yes, yesListener).setNegativeButton(no, noListener).create();

        if (!activity.isFinishing() && !activity.isRestricted()) {
            dialog.show();
            return true;
        }

        return false;
    }

    //
    public static void
            call(Context activity, String title, String message, int yes, int no,
                    DialogInterface.OnClickListener yesListener, DialogInterface.OnClickListener noListener,
                    boolean cancelable) {

        if (activity == null) {
            return;
        }

        Dialog dialog = new AlertDialog.Builder(activity).setTitle(title).setIcon(R.drawable.letv_dialog_icon)
                .setMessage(message).setCancelable(cancelable).setPositiveButton(yes, yesListener)
                .setNegativeButton(no, noListener).create();
        if (activity instanceof Activity) {
            if (!((Activity) activity).isFinishing() && !activity.isRestricted()) {
                dialog.show();
            }
        }
    }

    // public static void call(Context activity, String message,
    // DialogInterface.OnClickListener yesListener,
    // DialogInterface.OnClickListener noListener) {
    //
    // if (activity == null) {
    // return;
    // }
    //
    // Dialog dialog = new AlertDialog.Builder(activity)
    // .setTitle(R.string.dialog_default_title)
    // .setIcon(R.drawable.letv_dialog_icon).setMessage(message)
    // .setPositiveButton(R.string.dialog_default_ok, yesListener)
    // .setNegativeButton(R.string.dialog_default_no, noListener)
    // .create();
    //
    // if (activity instanceof Activity) {
    // if (!((Activity) activity).isFinishing()
    // && !activity.isRestricted()) {
    // try {
    // dialog.show();
    // } catch (Exception e) {
    // e.printStackTrace();
    // }
    // }
    // }
    //
    // }

    // public static void call(Context activity, String messageId, int yesId,
    // int noId, DialogInterface.OnClickListener yesListener,
    // DialogInterface.OnClickListener noListener) {
    //
    // if (activity == null) {
    // return;
    // }
    //
    // Dialog dialog = new AlertDialog.Builder(activity)
    // .setIcon(R.drawable.letv_dialog_icon).setMessage(messageId)
    // .setPositiveButton(yesId, yesListener)
    // .setNegativeButton(noId, noListener).create();
    //
    // if (activity instanceof Activity) {
    // if (!((Activity) activity).isFinishing()
    // && !activity.isRestricted()) {
    // try {
    // dialog.show();
    // } catch (Exception e) {
    // e.printStackTrace();
    // }
    // }
    // }
    //
    // }

    // public static void call(Context context, int message, int yes, int no,
    // DialogInterface.OnClickListener yesListener,
    // DialogInterface.OnClickListener noListener, boolean cancelable) {
    //
    // if (context == null) {
    // return;
    // }
    //
    // Dialog dialog = new AlertDialog.Builder(context)
    // .setTitle(R.string.dialog_default_title)
    // .setIcon(R.drawable.letv_dialog_icon).setMessage(message)
    // .setCancelable(cancelable).setPositiveButton(yes, yesListener)
    // .setNegativeButton(no, noListener).create();
    // if (context instanceof Activity) {
    // if (!((Activity) context).isFinishing() && !context.isRestricted()) {
    // dialog.show();
    // }
    // }
    // }

    // public static void call(Context activity, int messageId, int yesId,
    // DialogInterface.OnClickListener yesListener,
    // DialogInterface.OnClickListener noListener, boolean cancelable) {
    // if (activity == null) {
    // return;
    // }
    //
    // Dialog dialog = new AlertDialog.Builder(activity)
    // .setIcon(R.drawable.letv_dialog_icon).setMessage(messageId)
    // .setCancelable(cancelable)
    // .setPositiveButton(yesId, yesListener).create();
    // if (activity instanceof Activity) {
    // if (!((Activity) activity).isFinishing()
    // && !activity.isRestricted()) {
    // dialog.show();
    // }
    // }
    // }

    public static void call(Activity activity, int titleId, int messageId, DialogInterface.OnClickListener yes,
            DialogInterface.OnClickListener no) {
        try {
            if (activity == null) {
                return;
            }

            Dialog dialog = new AlertDialog.Builder(activity).setTitle(titleId).setIcon(R.drawable.letv_dialog_icon)
                    .setMessage(messageId).setPositiveButton(R.string.dialog_default_ok, yes)
                    .setNegativeButton(R.string.dialog_default_no, no).create();

            if (!activity.isFinishing() && !activity.isRestricted()) {
                dialog.show();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    //
    public static void call(Activity activity, int messageId, DialogInterface.OnClickListener yes) {

        if (activity == null) {
            return;
        }

        Dialog dialog = new AlertDialog.Builder(activity).setTitle(R.string.dialog_default_title)
                .setIcon(R.drawable.letv_dialog_icon).setMessage(messageId)
                .setPositiveButton(R.string.dialog_default_ok, yes).create();

        if (!activity.isFinishing() && !activity.isRestricted()) {
            dialog.show();
        }
    }

    public static void call(Activity activity, int title, int messageId, int yes,
            DialogInterface.OnClickListener yesListener, boolean cancelable) {

        if (activity == null) {
            return;
        }

        Dialog dialog = new AlertDialog.Builder(activity).setTitle(title).setIcon(R.drawable.letv_dialog_icon)
                .setMessage(messageId).setCancelable(cancelable).setPositiveButton(yes, yesListener).create();

        if (!activity.isFinishing() && !activity.isRestricted()) {
            dialog.show();
        }
    }

    //
    public static void call(Activity activity, String message, DialogInterface.OnClickListener yes) {

        if (activity == null) {
            return;
        }

        Dialog dialog = new AlertDialog.Builder(activity).setTitle(R.string.dialog_default_title)
                .setIcon(R.drawable.letv_dialog_icon).setMessage(message).setPositiveButton(R.string.dialog_default_ok, yes)
                .create();

        if (!activity.isFinishing() && !activity.isRestricted()) {
            dialog.show();
        }
    }

    //
    public static void call(Activity activity, String message, DialogInterface.OnClickListener yes, boolean cancelable) {

        if (activity == null) {
            return;
        }

        Dialog dialog = new AlertDialog.Builder(activity).setTitle(R.string.dialog_default_title)
                .setIcon(R.drawable.letv_dialog_icon).setMessage(message).setPositiveButton(R.string.dialog_default_ok, yes)
                .create();
        dialog.setCancelable(cancelable);
        if (!activity.isFinishing() && !activity.isRestricted()) {
            dialog.show();
        }
    }

    //
    public static void
            call(Activity activity, int messageId, int yes, int no, DialogInterface.OnClickListener yesListener,
                    DialogInterface.OnClickListener noListener, boolean cancelable) {

        if (activity == null) {
            return;
        }

        Dialog dialog = new AlertDialog.Builder(activity).setMessage(messageId).setCancelable(cancelable)
                .setPositiveButton(yes, yesListener).setNegativeButton(no, noListener).create();

        if (!activity.isFinishing() && !activity.isRestricted()) {
            dialog.show();
        }
    }

    public static void call(Activity activity, String messageId, DialogInterface.OnClickListener yes,
            DialogInterface.OnClickListener no) {

        if (activity == null) {
            return;
        }

        Dialog dialog = new AlertDialog.Builder(activity).setIcon(R.drawable.letv_dialog_icon).setMessage(messageId)
                .setPositiveButton(R.string.dialog_default_ok, yes).setNegativeButton(R.string.dialog_default_no, no)
                .create();

        if (!activity.isFinishing() && !activity.isRestricted()) {
            dialog.show();
        }

    }

    public static void call(Activity activity, String messageId, int yesId, int noId,
            DialogInterface.OnClickListener yes, DialogInterface.OnClickListener no) {

        if (activity == null) {
            return;
        }

        Dialog dialog = new AlertDialog.Builder(activity).setIcon(R.drawable.letv_dialog_icon).setMessage(messageId)
                .setPositiveButton(yesId, yes).setNegativeButton(noId, no).create();

        if (!activity.isFinishing() && !activity.isRestricted()) {
            dialog.show();
        }

    }

    public static void call(Activity activity, int messageId, int yesId, DialogInterface.OnClickListener yes,
            boolean cancelable) {
        if (activity == null) {
            return;
        }

        // Dialog dialog = new AlertDialog.Builder(activity)
        // .setIcon(R.drawable.letv_dialog_icon).setMessage(messageId)
        // .setCancelable(cancelable).setPositiveButton(yesId, yes)
        // .create();
        //
        // if (!activity.isFinishing() && !activity.isRestricted()) {
        // dialog.show();
        // }

        showDialog(activity, activity.getResources().getString(messageId), activity.getResources().getString(yesId),
                yes);
    }

    public static void call(Activity activity, int titleId, String messageId, int yesId, int noId,
            DialogInterface.OnClickListener yes, DialogInterface.OnClickListener no, boolean cancelable) {
        if (activity == null) {
            return;
        }

        // Dialog dialog = new AlertDialog.Builder(activity).setTitle(titleId)
        // .setIcon(R.drawable.letv_dialog_icon).setMessage(messageId)
        // .setCancelable(cancelable).setPositiveButton(yesId, yes)
        // .setNegativeButton(noId, no).create();
        //
        // if (!activity.isFinishing() && !activity.isRestricted()) {
        // dialog.show();
        // }

        showDialog(activity, messageId, activity.getResources().getString(yesId),
                activity.getResources().getString(noId), yes, no);
    }

    // ========================================================================================================
    // // -----------------------** 客户端dialog数据服务端化-----START
//    public static void
//            callDialogMsgPositiveButton(Activity activity, String msgId, DialogInterface.OnClickListener yes) {
//        TipBean dialogMsgByMsg = TipUtils.getTipBean(msgId);
//        if (activity == null || dialogMsgByMsg == null) {
//            return;
//        }
//        Dialog dialog = new AlertDialog.Builder(activity)
//                .setTitle(
//                        (!"".equals(dialogMsgByMsg.getTitle()) && dialogMsgByMsg.getTitle() != null) ? dialogMsgByMsg.getTitle()
//                                : activity.getString(R.string.dialog_default_title)).setIcon(R.drawable.letv_dialog_icon)
//                .setMessage(dialogMsgByMsg.getMessage()).setPositiveButton(R.string.dialog_default_ok, yes).create();
//
//        if (!activity.isFinishing() && !activity.isRestricted()) {
//            dialog.show();
//        }
//    }

    //
    public static void callDialogMsgPositiveButton(Activity activity, String msgId, int yes,
            DialogInterface.OnClickListener yesListener, DialogInterface.OnKeyListener onKeyListener) {
        TipBean dialogMsgByMsg = TipUtils.getTipBean(activity,msgId);
        if (activity == null || dialogMsgByMsg == null) {
            return;
        }
        Dialog dialog = new AlertDialog.Builder(activity)
                .setTitle(
                        (!"".equals(dialogMsgByMsg.getTitle()) && dialogMsgByMsg.getTitle() != null) ? dialogMsgByMsg.getTitle()
                                : activity.getString(R.string.dialog_default_title)).setOnKeyListener(onKeyListener)
                .setIcon(R.drawable.letv_dialog_icon).setMessage(dialogMsgByMsg.getMessage())
                .setPositiveButton(yes, yesListener).create();

        if (!activity.isFinishing() && !activity.isRestricted()) {
            dialog.show();
        }
    }

    //
//    public static void callDialogMsgPosNeg(Activity activity, String msgId, int yes, int no,
//            DialogInterface.OnClickListener yesListener, DialogInterface.OnClickListener noListener) {
//        TipBean dialogMsgByMsg = TipUtils.getTipBean(msgId);
//        if (activity == null || dialogMsgByMsg == null) {
//            return;
//        }
//
//        Dialog dialog = new AlertDialog.Builder(activity)
//                .setTitle(
//                        (!"".equals(dialogMsgByMsg.getTitle()) && dialogMsgByMsg.getTitle() != null) ? dialogMsgByMsg.getTitle()
//                                : activity.getString(R.string.dialog_default_title)).setIcon(R.drawable.letv_dialog_icon)
//                .setMessage(dialogMsgByMsg.getMessage()).setCancelable(false).setPositiveButton(yes, yesListener)
//                .setNegativeButton(no, noListener).create();
//
//        if (!activity.isFinishing() && !activity.isRestricted()) {
//            dialog.show();
//        }
//    }

//    public static boolean callDialogMsgPosNeg(Activity activity, String msgId, int yes, int no,
//            DialogInterface.OnClickListener yesListener, DialogInterface.OnClickListener noListener, View view,
//            boolean cancelable) {
//        TipBean dialogMsgByMsg = TipUtils.getTipBean(msgId);
//        if (activity == null || dialogMsgByMsg == null) {
//            return false;
//        }
//
//        Dialog dialog = new AlertDialog.Builder(activity)
//                .setTitle(
//                        (!"".equals(dialogMsgByMsg.getTitle()) && dialogMsgByMsg.getTitle() != null) ? dialogMsgByMsg.getTitle()
//                                : activity.getString(R.string.dialog_default_title)).setView(view)
//                .setCancelable(cancelable).setIcon(R.drawable.letv_dialog_icon).setMessage(dialogMsgByMsg.getMessage())
//                .setPositiveButton(yes, yesListener).setNegativeButton(no, noListener).create();
//
//        if (!activity.isFinishing() && !activity.isRestricted()) {
//            dialog.show();
//            return true;
//        }
//        return false;
//    }

    //
//    public static void callDialogMsgPosNegDefault(Activity activity, String msgId, DialogInterface.OnClickListener yes,
//            DialogInterface.OnClickListener no) {
//        TipBean dialogMsgByMsg = TipUtils.getTipBean(msgId);
//        if (activity == null || dialogMsgByMsg == null) {
//            return;
//        }
//        Dialog dialog = new AlertDialog.Builder(activity)
//                .setTitle(
//                        (!"".equals(dialogMsgByMsg.getTitle()) && dialogMsgByMsg.getTitle() != null) ? dialogMsgByMsg.getTitle()
//                                : activity.getString(R.string.dialog_default_title)).setIcon(R.drawable.letv_dialog_icon)
//                .setMessage(dialogMsgByMsg.getMessage()).setPositiveButton(R.string.dialog_default_ok, yes)
//                .setNegativeButton(R.string.dialog_default_no, no).create();
//
//        if (!activity.isFinishing() && !activity.isRestricted()) {
//            try {
//                dialog.show();
//            } catch (Exception e) {
//                e.printStackTrace();
//            }
//        }
//
//    }

//    public static void callDialogMsgPosNegCancel(Activity activity, String msgId, int yes, int no,
//            DialogInterface.OnClickListener yesListener, DialogInterface.OnClickListener noListener,
//            boolean cancelable, Object[] messageWhichs) {
//        Dialog dialog = null;
//        TipBean dialogMsgByMsg = TipUtils.getTipBean(msgId);
//        if (activity == null || dialogMsgByMsg == null) {
//            return;
//        }
//        if (dialogMsgByMsg.getMessage().contains("%1$s")) {
//
//            dialog = new AlertDialog.Builder(activity)
//                    .setTitle(
//                            /* dialogMsgByMsg.title */(!"".equals(dialogMsgByMsg.getTitle()) && dialogMsgByMsg.getTitle() != null) ? dialogMsgByMsg.getTitle()
//                                    : activity.getString(R.string.dialog_default_title))
//                    .setMessage(String.format(dialogMsgByMsg.getMessage(), messageWhichs)).setCancelable(cancelable)
//                    .setPositiveButton(yes, yesListener).setNegativeButton(no, noListener).create();
//        } else {
//            dialog = new AlertDialog.Builder(activity)
//                    .setTitle(
//                            /* dialogMsgByMsg.title */(!"".equals(dialogMsgByMsg.getTitle()) && dialogMsgByMsg.getTitle() != null) ? dialogMsgByMsg.getTitle()
//                                    : activity.getString(R.string.dialog_default_title))
//                    .setMessage(dialogMsgByMsg.getMessage()).setCancelable(cancelable).setPositiveButton(yes, yesListener)
//                    .setNegativeButton(no, noListener).create();
//
//        }
//
//        if (!activity.isFinishing() && !activity.isRestricted()) {
//            dialog.show();
//        }
//    }

    //
    // public static void notifyErrLong(Context context, String text) {
    // if (LetvApplication.getInstance() != null) {
    // mLetvToast = new LetvToast(LetvApplication.getInstance());
    // mLetvToast.setDuration(Toast.LENGTH_LONG);
    // }
    //
    // mLetvToast.setErr(true);
    // mLetvToast.setMsg(text);
    // mLetvToast.show();
    // showToast(context, text, LetvApplication.getInstance() == null, false);
    // }

//    public static void notifyDBShortNormal(Context context, String toastMsgID) {
//        TipBean dialogMsgByMsg = TipUtils.getTipBean(toastMsgID);
//        if (context == null || dialogMsgByMsg == null) {
//            return;
//        }
//        // if (mToast != null) {
//        // mToast.cancel();
//        // }
//        // if (LetvApplication.getInstance() != null) {
//        // mToast = Toast.makeText(LetvApplication.getInstance(),
//        // dialogMsgByMsg.message, Toast.LENGTH_LONG);
//        // }
//        // mToast.setText(dialogMsgByMsg.message);
//        // mToast.setGravity(Gravity.CENTER, 0, 0);
//        // mToast.setDuration(Toast.LENGTH_SHORT);
//        // mToast.show();
//        // showToast(context, dialogMsgByMsg.message, false, false);
//        // hzz
//        // UIsPlayerLibs.showToast(context, dialogMsgByMsg.message);
//        // end
//    }

//    public static void notifyDBShortNormal(Context context, String toastMsgID, String msgTxt) {
//        TipBean dialogMsgByMsg = TipUtils.getTipBean(toastMsgID);
//        if (context == null) {
//            return;
//        }
//
//        LogInfo.log("notifyDBShortNormal", "notifyDBShortNormal dialogMsgByMsg : " + dialogMsgByMsg);
//
//        String txt = "";
//        if (dialogMsgByMsg == null && !TextUtils.isEmpty(msgTxt)) {
//            txt = msgTxt;
//        } else {
//            txt = dialogMsgByMsg.getMessage();
//        }
//        // if (mToast != null) {
//        // mToast.cancel();
//        // }
//        // if (LetvApplication.getInstance() != null) {
//        // mToast = Toast.makeText(LetvApplication.getInstance(), txt,
//        // Toast.LENGTH_LONG);
//        // }
//        // mToast.setText(txt);
//        // mToast.setGravity(Gravity.CENTER, 0, 0);
//        // mToast.setDuration(Toast.LENGTH_SHORT);
//        // mToast.show();
//        // 原代码在application不为null时时间设置为长，目前统一改为短
//        // showToast(context, txt, false, false);
//        // hzz
//        // UIsPlayerLibs.showToast(context, txt);
//        // end
//    }

    /**
     * 赞动画
     *
     * @param view
     */
    public static void animTop(Context context, final View view) {
        TipBean dialogMsgByMsg = TipUtils.getTipBean(context,DialogMsgConstantId.CONSTANT_100062);
        // if (dialogMsgByMsg == null) {
        // showToast(context, "已收藏到播放单");
        // } else {
        // showToast(context, dialogMsgByMsg.message);
        // }

        if (view != null) {
            if (null != view.getAnimation() && !view.getAnimation().hasEnded()) {
                return;
            }
            view.post(new Runnable() {
                @Override
                public void run() {
                    animCollection(view, collectionAniScaleRec, 0);
                }
            });
        }
    }

    /**
     * 收藏渐变规则
     */
    private static float[] collectionAniScaleRec = new float[] { 1.0f, 0.6f, 1.5f, 0.8f, 1.0f };

    private static float[] unConllectionAniScalRec = new float[] { 1.0f, 0.6f, 1.5f, 0.6f, 1.0f };
    /**
     * 渐变率(必须要能被scaleSize数组的相邻两个数值之差整除)
     */
    private static float scaleRate = 0.1f;
    /**
     * 动画总执行时间ms(由于实际几个Animation之间执行回调需要时间，所以实际总动画时间会比这个时间长)
     */
    private static final int animTotallTime = 220;

    /**
     * 收藏动画
     * 
     * @param view
     */
    public static void animCollection(Context context, final View view) {
        // modified by zengsonghai 2014/7/6 --- start 收藏不成功不应该弹出提示
        // MessageBean dialogMsgByMsg =
        // DBManager.getInstance().getDialogMsgTrace().getDialogMsgByMsgId(DialogMsgConstantId.CONSTANT_20009);
        // if (dialogMsgByMsg == null) {
        // showToast(context, "已收藏到播放单");
        // } else {
        // showToast(context, dialogMsgByMsg.message);
        // }
        // modified by zengsonghai 2014/7/6 --- end 收藏不成功不应该弹出提示

        if (view != null) {
            if (null != view.getAnimation() && !view.getAnimation().hasEnded()) {
                return;
            }
            view.post(new Runnable() {
                @Override
                public void run() {
                    animCollection(view, collectionAniScaleRec, 0);
                }
            });
        }
    }

    /**
     * 取消收藏
     * 
     * @param view
     */
    public static void animUncollection(Context context, final View view) {
        TipBean dialogMsgByMsg = TipUtils.getTipBean(context,DialogMsgConstantId.CONSTANT_20010);
        if (dialogMsgByMsg == null) {
            UIs.showPopWin(view, R.layout.letv_layout_popwindow, "已取消收藏", true);
        } else {
            UIs.showPopWin(view, R.layout.letv_layout_popwindow, dialogMsgByMsg.getMessage(), true);
        }

        if (view != null) {
            if (null != view.getAnimation() && !view.getAnimation().hasEnded()) {
                return;
            }
            view.post(new Runnable() {

                @Override
                public void run() {
                    animCollection(view, unConllectionAniScalRec, 0);
                }
            });
        }
    }

    /**
     * 收藏/取消收藏 动画实际逻辑
     */
    private static void animCollection(final View view, final float[] aniScaleRec, final int index) {
        animFrames(view, index, aniScaleRec, new Runnable() {

            @Override
            public void run() {
                if (index + 1 < aniScaleRec.length - 1) {
                    animCollection(view, aniScaleRec, index + 1);
                }
            }
        });

    }

    /**
     * 收藏view的每次变换动画逻辑
     * 
     * @param view
     * @param index
     * @param aniScaleRec
     * @param callback
     * 动画执行完成回调
     */
    private static void animFrames(final View view, final int index, float[] aniScaleRec, final Runnable callback) {
        /**
         * 总帧数
         */
        float totalFrame = 0;
        for (int i = 0; i < aniScaleRec.length - 1; i++) {
            totalFrame += Math.abs(aniScaleRec[i + 1] - aniScaleRec[i]);
        }
        /**
         * 执行每一帧切换的时间
         */
        final int animFrameTime = animTotallTime / ((int) (totalFrame / scaleRate));
        float animEnd = aniScaleRec[index + 1];
        float animStart = aniScaleRec[index];
        final int scaleCount = Math.abs(((int) (animEnd * 100) - (int) (animStart * 100)) / ((int) (scaleRate * 100)));
        int duration = scaleCount * animFrameTime;
        ScaleAnimation sa = new ScaleAnimation(animStart, animEnd, animStart, animEnd, Animation.RELATIVE_TO_SELF,
                0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        sa.setFillAfter(true);
        sa.setDuration(duration);
        sa.setAnimationListener(new AnimationListener() {

            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                callback.run();
            }
        });
        view.startAnimation(sa);
    }

    /**
     * 头像右上角收藏泡泡 动画
     */
    public static void animCollectionPop(final View view) {
        if (view != null) {
            view.setVisibility(View.VISIBLE);
            ScaleAnimation sa = new ScaleAnimation(0.0f, 1.0f, 0.0f, 1.0f, Animation.RELATIVE_TO_SELF, 0.0f,
                    Animation.RELATIVE_TO_SELF, 1.0f);
            sa.setDuration(400);
            view.startAnimation(sa);
        }
    }

    // public static void deleteShortCutIcon(Context ctx, int appId) {
    // Intent intent = new
    // Intent("com.android.launcher.action.UNINSTALL_SHORTCUT");
    // // 获取当前应用名称
    // String title = null;
    // try {
    // final PackageManager pm = ctx.getPackageManager();
    // title =
    // pm.getApplicationLabel(pm.getApplicationInfo(ctx.getPackageName(),
    // PackageManager.GET_META_DATA))
    // .toString();
    // } catch (Exception e) {
    // }
    // intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, title);
    // // 要删除的应用程序的ComponentName，即应用程序包名+activity的名字
    // ComponentName comp = new ComponentName(ctx.getPackageName(), title);
    // intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,
    // new Intent().setComponent(comp).setAction("android.intent.action.MAIN"));
    // ctx.sendBroadcast(intent);
    // }
    //
    // /**
    // * 创建桌面快捷方式
    // *
    // * @param ctx
    // */
    // public static void createShortCutIcon(Context ctx) {
    // // 删除老的乐视影视快捷方式
    // deleteShortCutIcon(ctx, R.string.old_app_name);
    // deleteShortCutIcon(ctx, R.string.app_name);
    // if (!IfaddShortCut(ctx, R.string.app_name) &&
    // !PreferencesManager.getInstance().getShortCutIcon()) {
    // Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
    // shortcutIntent.setClass(ctx, MainActivity.class);
    // shortcutIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    // shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    // shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    //
    // Intent intent = new Intent();
    // intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    // intent.putExtra(Intent.EXTRA_SHORTCUT_NAME,
    // ctx.getResources().getString(R.string.app_name));
    // intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
    // Intent.ShortcutIconResource.fromContext(ctx.getApplicationContext(),
    // R.drawable.letv_icon));
    // intent.putExtra("duplicate", false);
    // intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
    // ctx.sendBroadcast(intent);
    // PreferencesManager.getInstance().setShortCutIcon(true);
    // }
    // }
    //
    // /**
    // * 创建桌面搜索快捷方式
    // *
    // * @param ctx
    // */
    // public static void createSearchShortCutIcon(Context ctx,String appName) {
    //
    // // 删除老的乐视影视快捷方式
    // deleteShortCutIcon(ctx, R.string.old_app_name);
    // deleteShortCutIcon(ctx, R.string.app_name);
    // if (!IfaddShortCut(ctx, R.string.letv_search_name)&& !installApp(ctx,
    // packageSearchName)) {
    // Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
    // shortcutIntent.setClassName(ctx,
    // "com.letv.android.client.ui.impl.SearchMainActivity");
    // // shortcutIntent.setClass(ctx, SearchMainActivity.class);
    // shortcutIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    // shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    // shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    // shortcutIntent.putExtra("source", "lesou");
    //
    // Intent intent = new Intent();
    // intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    // intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, appName);
    // intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
    // Intent.ShortcutIconResource.fromContext(ctx.getApplicationContext(),
    // R.drawable.letv_search_icon));
    // intent.putExtra("duplicate", false);
    // intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
    // ctx.sendBroadcast(intent);
    //
    // PreferencesManager.getInstance().setSearchShortcut(false);
    // }
    // }
    //
    // //
    // public static boolean installApp(Context context, String packageName) {
    //
    // PackageManager packageManager = context.getPackageManager();
    // try {
    // PackageInfo pInfo = packageManager.getPackageInfo(packageName,
    // PackageManager.COMPONENT_ENABLED_STATE_DEFAULT);
    // //判断是否获取到了对应的包名信息
    // if(pInfo!=null){
    // return true;
    // }
    // } catch (Exception e) {
    // e.printStackTrace();
    // }
    // return false;
    // }
    // /**
    // * 是否有快捷方式
    // * */
    // public static boolean IfaddShortCut(Context ctx, int appId) {
    // boolean isInstallShortcut = false;
    //
    // // 由于系统差异，uriStr在不同机型上的launcher有所差异
    // final String uriStr1 =
    // "content://com.android.launcher.settings/favorites?notify=true";
    // final String uriStr2 =
    // "content://com.android.launcher2.settings/favorites?notify=true";
    // Cursor cursor = null;
    // if (VERSION.SDK_INT >= 8) {
    // cursor = getCursorByUri(ctx, uriStr2, appId);
    // } else {
    // cursor = getCursorByUri(ctx, uriStr1, appId);
    // }
    // isInstallShortcut = (cursor != null && cursor.getCount() > 0);
    // LogInfo.log("main", ctx.getString(appId) + " has  shortcut =" +
    // isInstallShortcut);
    // if (cursor != null) {
    // cursor.close();
    // }
    // return isInstallShortcut;
    // }
    // =============================================================================
    /**
     * 删除桌面快捷方式
     *
     */
    public static void deleteShortCutIcon(Context ctx, int string_app_name, String className) {
        Intent shortcutIntent = null;
        shortcutIntent = new Intent(Intent.ACTION_MAIN);
        shortcutIntent.setClassName(ctx, className);
        shortcutIntent.addCategory(Intent.CATEGORY_LAUNCHER);
        shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);

        Intent delShortcut = new Intent();
        delShortcut.setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");
        delShortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, ctx.getResources().getString(string_app_name));
        delShortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
        ctx.sendBroadcast(delShortcut);
    }

    /**
     * 创建桌面快捷方式
     *
     * */
    // hzz
    /*
     * public static void createShortCutIcon(Context ctx, int string_app_name,
     * int drawbale_letv_icon, Class className) {
     * Intent shortcutIntent = null;
     * shortcutIntent = new Intent(Intent.ACTION_MAIN);
     * shortcutIntent.setClass(ctx, className);
     * shortcutIntent.addCategory(Intent.CATEGORY_LAUNCHER);
     * shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
     * // shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY);
     * shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
     * 
     * final Intent intent = new Intent();
     * intent.putExtra("duplicate", false);
     * intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
     * intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, ctx.getResources()
     * .getString(string_app_name));
     * LogInfo.log("LM",
     * "name  " + LetvUtil.getPhoneBrand() + "   "
     * + LetvUtil.getPhoneModel());
     * if (LetvUtil.getPhoneBrand().equalsIgnoreCase("coolpad")) {
     * if (LetvUtil.getPhoneModel().contains("8297")
     * || LetvUtil.getPhoneModel().contains("9976")) {
     * intent.putExtra(Intent.EXTRA_SHORTCUT_ICON,
     * getNormalBitMap(ctx, drawbale_letv_icon));
     * } else {
     * intent.putExtra(
     * Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
     * Intent.ShortcutIconResource.fromContext(
     * ctx.getApplicationContext(), drawbale_letv_icon));
     * }
     * } else if (LetvUtil.getPhoneBrand().equalsIgnoreCase("huawei")) {
     * if (LetvUtil.getPhoneModel().contains("P7")
     * || LetvUtil.getPhoneModel().contains("p7")
     * || LetvUtil.getPhoneModel().contains("p6")
     * || LetvUtil.getPhoneModel().contains("P6")
     * || LetvUtil.getPhoneModel().contains("H30-U10")) {
     * intent.putExtra(Intent.EXTRA_SHORTCUT_ICON,
     * getNormalBitMapForP7(ctx, drawbale_letv_icon));
     * } else {
     * intent.putExtra(
     * Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
     * Intent.ShortcutIconResource.fromContext(
     * ctx.getApplicationContext(), drawbale_letv_icon));
     * }
     * } else if (LetvUtil.getPhoneBrand().equalsIgnoreCase("oppo")) {
     * if (LetvUtil.getPhoneModel().contains("X909T")) {
     * intent.putExtra(Intent.EXTRA_SHORTCUT_ICON,
     * getNormalBitMapForP7(ctx, drawbale_letv_icon));
     * } else {
     * intent.putExtra(
     * Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
     * Intent.ShortcutIconResource.fromContext(
     * ctx.getApplicationContext(), drawbale_letv_icon));
     * }
     * } else if (LetvUtil.getPhoneBrand().equalsIgnoreCase("samsung")) {
     * if (LetvUtil.getPhoneModel().contains("I9100")) {
     * intent.putExtra(Intent.EXTRA_SHORTCUT_ICON,
     * getNormalBitMapForP7(ctx, drawbale_letv_icon));
     * } else {
     * intent.putExtra(
     * Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
     * Intent.ShortcutIconResource.fromContext(
     * ctx.getApplicationContext(), drawbale_letv_icon));
     * }
     * } else {
     * intent.putExtra(
     * Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
     * Intent.ShortcutIconResource.fromContext(
     * ctx.getApplicationContext(), drawbale_letv_icon));
     * }
     * intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
     * ctx.sendBroadcast(intent);
     * }
     */
    // end

    /**
     * 解决乐看搜索和乐视视频快捷方式icon相同问题
     * 
     * @param context
     * @param id
     * @return
     */
    private static Bitmap getNormalBitMapForP7(Context context, int id) {
        Bitmap bitMap = ((BitmapDrawable) context.getResources().getDrawable(id)).getBitmap();
        int bmpWidth = bitMap.getWidth();
        int bmpHeight = bitMap.getHeight();
        int sWidth = 144;
        int sHeight = 144;
        float scaleWidth = (float) sWidth / bmpWidth;
        float scaleHeight = (float) sHeight / bmpHeight;
        Matrix matrix = new Matrix();
        matrix.postScale(scaleWidth, scaleHeight);
        Bitmap resizeBitmap = Bitmap.createBitmap(bitMap, 0, 0, bmpWidth, bmpHeight, matrix, false);
        return resizeBitmap;
    }

    private static Bitmap getNormalBitMap(Context context, int id) {
        Bitmap bitMap = ((BitmapDrawable) context.getResources().getDrawable(id)).getBitmap();
        return bitMap;
    }

    // /**
    // * 加载资源文件图片
    // * */
    // public static Drawable loadResourcesDrawable(Context context,
    // int resourcesId) {
    // return Drawable.createFromStream(context.getResources()
    // .openRawResource(resourcesId), null);
    // }

    /**
     * 加载资源文件图片
     * */
    public static Bitmap loadResourcesBitmap(Context context, int resourcesId) {
        return BitmapFactory.decodeStream(context.getResources().openRawResource(resourcesId));
    }

    /**
     * 回收资源文件图片
     * */
    public static void recycleBitmap(Bitmap bitmap) {
        if (bitmap != null && !bitmap.isRecycled()) {
            bitmap.recycle();
        }
        bitmap = null;
    }

    /**
     * 回收ImageView及其image bitmap
     * */
    // public static void recycleImageView(ImageView imageView) {
    // if (null != imageView) {
    // BitmapDrawable bitmapDrawable = (BitmapDrawable) imageView
    // .getDrawable();
    // Bitmap bitmap = null;
    // if (null != bitmapDrawable) {
    // bitmap = bitmapDrawable.getBitmap();
    // }
    // if (bitmap != null && !bitmap.isRecycled()) {
    // bitmap.recycle();
    // }
    // bitmap = null;
    // imageView = null;
    // }
    // }

    /**
     * 加载资源文件图片
     * */
    // public static void recycleDrawable(Drawable drawable) {
    // if (drawable != null) {
    // drawable.setCallback(null);
    // }
    // drawable = null;
    // }

    public static Bitmap resizeBitmap(Bitmap bitmap, int width, int height) {
        final Bitmap b = Bitmap.createBitmap(width, height, Config.RGB_565);
        final Canvas canvas = new Canvas(b);
        Rect src = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
        Rect dst = new Rect(0, 0, width, height);
        Paint paint = new Paint();
        canvas.drawBitmap(bitmap, src, dst, paint);
        return b;
    }

    /**
     * 取消activity跳转动画
     * 
     * @param activity
     */
    public static void overridePendingTransition(Activity activity) {
        Class clazz = activity.getClass();
        try {
            java.lang.reflect.Method overPendingMethod =
                    clazz.getMethod("overridePendingTransition", int.class, int.class);
            (overPendingMethod).invoke(activity, 0, 0);
        } catch (SecurityException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }
}
